﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace WorkRecord
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }
        private IniFile iniFile = new IniFile(@"./User.ini");
        private void button_Login_Click(object sender, EventArgs e)
        {

            string EnCodeUsername = iniFile.IniReadValue("User", "username");
            string EnCodePassword = iniFile.IniReadValue("User", "password");
            if (MD5(t_username.Text) == EnCodeUsername && MD5(t_password.Text) == EnCodePassword)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("登录名或密码错误","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }

        public static string MD5(string str)
        {
            byte[] result = Encoding.Default.GetBytes(str);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            return BitConverter.ToString(output).Replace("-", "");
        }
    }
}
